//
//  LBBrightnessFilter.mm
//  OpenGLGame
//
//  Created by Nguyen Cong Huy on 3/28/13.
//  Copyright (c) 2013 UIT. All rights reserved.
//

#include "LBBrightnessFilter.h"
#include "LBGraphics.h"

char fShaderStrBrightness[] = ""
"precision mediump float;"

"varying vec2 vtexCoor;"
"varying vec4 vposition;"
"uniform sampler2D texture;"
"uniform float brightness;"


//brightness function (default 0.0)
"vec4 brightnessColor(vec4 color, float brightness){"
"color.r = color.r + brightness;"
"color.g = color.g + brightness;"
"color.b = color.b + brightness;"
"color = clamp(color, 0.0, 1.0);"
"return color;"
"}"
//END brightness function


"void main()"
"{"
"    lowp vec4 textureColor = texture2D(texture, vtexCoor);"
"    textureColor = brightnessColor(textureColor, brightness);"
""

"    gl_FragColor = textureColor;"
"}";

LBBrightnessFilter::LBBrightnessFilter(){
    init(0, fShaderStrBrightness);
    LBGraphics::getInstance()->useProgram(program);
    brightnessUniform = program->uniformIndex("brightness");
    setBrightness(1.0f);
}

void LBBrightnessFilter::setBrightness(float brightness){
    LBGraphics::getInstance()->useProgram(program);
    glUniform1f(brightnessUniform, brightness);
}